$(document).ready(function () {
    App.init();
    TableManageFixedHeader.init();
    var datenum = new Date().getTime();
    var enddatetime = datenum + 365 * 24 * 60 * 60 * 1000;
    var date = new Date(datenum)
    var enddate = new Date(enddatetime)
    date1 = dateFtt("yyyy-MM-dd", date)
    enddate1 = dateFtt("yyyy-MM-dd", enddate)
    $("#insureStartDate").val(date1)
    $("#insureEndDate").val(enddate1)
    $("#dateIssuance").val(date1);
    var viewtype = $("#viewstyle").val();
    if (viewtype == 80) {
        $("#tab1").removeClass("active in");
        $("#tab2").removeClass("active in");
        $("#tab3").addClass("active in");
        $("#ulid li:eq(0)").removeClass("active")
        $("#ulid li:eq(3) a").removeClass("hidden")
        $("#ulid li:eq(3)").addClass("active")
    }
    var createorder = $("#createorder").val();
    if (createorder == 1) {
        $("#tab1").removeClass("active in");
        $("#tab2").removeClass("active in");
        $("#tab3").removeClass("active in");
        $("#tab2").addClass("active in")
        $("#ulid li:eq(0)").removeClass("active")
        $("#ulid li:eq(1)").addClass("active")
    }

});
//变换tab页
function changeTab(type) {
    if (type == 1) {
        $("#tab2").removeClass("active in");
        $("#tab3").removeClass("active in");
        $("#tab1").addClass("active in");
    } else if (type == 2) {
        $("#tab1").removeClass("active in");
        $("#tab3").removeClass("active in");
        $("#tab2").addClass("active in");
    } else if (type == 3) {
        $("#tab1").removeClass("active in");
        $("#tab2").removeClass("active in");
        $("#tab3").addClass("active in");
    }
}

//去往编辑页面
function toedit(id) {
    window.location.href = "<%=path%>/sysuser/toedit/" + id;
}

//去往新增页面
function toadd() {
    window.location.href = "<%=path%>/sysuser/toadd";
}

//删除
function del(id) {

    Ewin.confirm({message: "确认要删除选择的数据吗？"}).on(function (e) {
        if (!e) {
            return;
        }
        jQuery.ajax({
            type: "GET",
            url: "<%=path%>/sysuser/del/" + id,
            dataType: "json",
            success: function (data) {
                if (data.success == true) {
                    alert('删除成功!');
                } else {
                    alert('删除失败!');
                }
                location.reload();
            }
        });
    });
}

$("#typeInvestment").click(
    function addselect() {
        var date = $("#typeInvestment").val();
        $("#laonAccount").hide();
        if (date != 3) {
        } else {
            $("#laonAccount").show();
        }
    }
)
$("#typeInsurance1").click(function () {
    $("#typeInsurance0").removeAttr("checked");
    $("#typeInsurance1").attr("checked", "checked");
    $("#carOwner1").removeAttr("data-parsley-required");
    $("#carOwner1").removeAttr("data-parsley-required-message");
    $("#engineNum1").attr("type", "hidden");
    $("#preInsyrer").removeAttr("type");
    $("#precompanyId").show();
    $("#engineNum").hide();
    $("#plateNum").attr("data-parsley-required",true);
    $("#plateNum").attr("data-parsley-required-message","车牌号不能为空");
    $("#insurant1").removeAttr("data-parsley-required");
    $("#insurant1").removeAttr("data-parsley-required-message");
    $("#orgIdCode").removeAttr("data-parsley-required");
    $("#orgIdCode").removeAttr("data-parsley-required-message");
})

$("#typeInsurance0").click(function () {
    $("#typeInsurance1").removeAttr("checked");
    $("#typeInsurance0").attr("checked", "checked");
    $("#carOwner1").attr("data-parsley-required",true);
    $("#carOwner1").attr("data-parsley-required-message","车主不能为空");
    $("#preInsyrer").attr("type", "hidden");
    $("#engineNum").removeClass("hidden");
    $("#engineNum1").removeAttr("type");
    $("#engineNum").show();
    $("#precompanyId").hide();
    $("#plateNum").removeAttr("data-parsley-required");
    $("#plateNum").removeAttr("data-parsley-required-message");
    $("#insurant1").attr("data-parsley-required",true);
    $("#insurant1").attr("data-parsley-required-message","被保险人不能为空");
    $("#orgIdCode").attr("data-parsley-required",true);
    $("#orgIdCode").attr("data-parsley-required-message","被保人身份信息不能为空");
})


//根据保险公司名称调产品信息
function invokecompany() {
    var insuranid = $("#companyIdd").find("option:selected").val()
    var inscode = $("#companyIdd").find("option:selected").attr("inscode");
    var insyrerName = $("#companyIdd").find("option:selected").text()
    $("#companyIddd").val(inscode)
    $("#insyrerName").val(insyrerName)
    var valuedaf = $("#companyIdd option:selected").html();
    if ("请选择" == valuedaf) {
        $("#typeInsurance21").removeAttr("checked")
        $("#typeInsurance22").removeAttr("checked")
        $("#typeInsurance2").addClass("hidden", "hidden");
        return false;
    }
    $.ajax({
        type: "POST",
        url: "/ins/order/prod",
        data: {"insuranid": insuranid},
        dateType: "json",
        success: function (result) {
            $("#typeInsurance21").removeAttr("checked")
            $("#typeInsurance22").removeAttr("checked")
            var item = "<option value= ''>请选择</option>\n";
            console.log(result.length)
            result.forEach(function (pro) {
                console.log("pro.type-------------------" + pro.type)
                console.log("result.length-------------------" + result.length)
                $("#labelcla0").find('input').attr('type', 'checkbox');
                if (pro.type == 0) {
                    $("#typeInsurance2").removeClass("hidden");
                    $('#labelcla2').addClass('hidden');
                    $('#labelcla1').removeClass('hidden');
                    var value0 = pro.tid;
                    console.log("pro.tid" + value0);
                    $("#typeInsurance21").val(value0 + "0");
                }
                if (pro.type == 1) {
                    $("#typeInsurance2").removeClass("hidden");
                    $('#labelcla1').addClass('hidden');
                    $('#labelcla2').removeClass('hidden');
                    var value1 = pro.tid;
                    console.log("pro.tid" + value1);
                    $("#typeInsurance22").val(value1 + "1");
                }
            });
            if (result.length == 2) {
                //$("#typeInsurance2").removeClass("hidden")
                $("#labelcla0").find('input').attr('type', 'checkbox');
                $("#labelcla1").removeClass("hidden");
                $("#typeInsurance21").removeClass("hidden").attr("type", "checkbox");
                $("#labelcla2").removeClass("hidden");
                $("#typeInsurance22").removeClass("hidden").attr("type", "checkbox")
            }
            //垫资账期选择
            $("#laonAccount1 option").remove()
            result[0].earingPointList.forEach(function (terms) {
                console.log("result[0].earingPointList" + result[0].earingPointList)
                item += "<option value='" + terms.paymentDays + "'>" + "账期" + terms.paymentDays + "天" + "</option>\n";
            })
            $("#laonAccount1").append(item);

        }
    })
}
//时间格式化js
function dateFtt(fmt, date) { //author: meizz
    var o = {
        "M+": date.getMonth() + 1,                 //月份
        "d+": date.getDate(),                    //日
        "h+": date.getHours(),                   //小时
        "m+": date.getMinutes(),                 //分
        "s+": date.getSeconds(),                 //秒
        "q+": Math.floor((date.getMonth() + 3) / 3), //季度
        "S": date.getMilliseconds()             //毫秒
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
//保险期限时间自动换算
$("#insureStartDate").change(function () {
    var start = $(this).val()
    var test1 = new Date(start)
    var startnum = test1.getTime()
    var endnum = startnum + 365 * 24 * 60 * 60 * 1000;
    console.log(start)
    console.log(endnum)
    new Date(endnum)
    var enddate = dateFtt("yyyy-MM-dd", new Date(endnum));
    $("#insureEndDate").val(enddate)
})
//时间比较
$("#insureEndDate").change(function () {
    var starttime = $("#insureStartDate").val().replace(/-/g, "");
    var endtime = $(this).val().replace(/-/g, "");
    if (endtime > 0) {
        if (starttime >= endtime) {
            alert("起保日期不能晚于止保日期");
            $(this).val("")
            return false
        }
    }
})
//时间插件配置
$(".selectData").datepicker({
    autoclose: true, //自动关闭
    beforeShowDay: $.noop, //在显示日期之前调用的函数
    calendarWeeks: false, //是否显示今年是第几周
    clearBtn: false, //显示清除按钮
    daysOfWeekDisabled: [], //星期几不可选
    endDate: Infinity, //日历结束日期
    forceParse: true, //是否强制转换不符合格式的字符串
    format: 'yyyy-mm-dd', //日期格式
    keyboardNavigation: true, //是否显示箭头导航
    language: "zh-CN", //语言
    minViewMode: 0,
    orientation: "auto", //方向
    rtl: false,
    startDate: -Infinity, //日历开始日期
    startView: 0, //开始显示
    todayBtn: false, //今天按钮
    todayHighlight: true, //今天高亮
    weekStart: 0 //星期几是开始
});
// ----------------------------------分页------------------------------------
var table;
$(document).ready(function () {
    table = $("#modeltable").DataTable({
        "pagingType": "simple_numbers",//设置分页控件的模式
        searching: false,//屏蔽datatales的查询框
        aLengthMenu: [15],//设置一页展示10条记录
        "bLengthChange": false,//屏蔽tables的一页展示多少条记录的下拉列表
        "oLanguage": {  //对表格国际化
            "sLengthMenu": "每页显示 _MENU_条",
            "sZeroRecords": "无匹配结果，请更换筛选条件再试",
            //  "sProcessing": "&lt;img src=’./loading.gif’ /&gt;",
            "sInfo": "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
            "sInfoEmpty": "当前第 0 - 0 条　共计 0 条",
            "sInfoFiltered": "(从 _MAX_ 条记录中过滤)",
            "sSearch": "搜索：",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            }
        },
        //"processing": true, //打开数据加载时的等待效果
        "serverSide": true,//打开后台分页
        // "order": [[ 5, "desc" ]],//默认排序
        ordering: false,
        "ajax": {
            "type": "POST",
            "url": "/ins/order/tolist",
            "dataSrc": "aaData",
            "data": function (params) {
                var ordCode = $("#baodanhao").val();
                var insurant = $("#beibaoxian").val();
                var createDate = $("#dingdantimeStart").val();
                var updateDate = $("#dingdantimeEnd").val();
                var orderstatus = $("#ordstatus option:selected").val();
                //添加额外的参数传给服务器
                params.ordNum = ordCode;
                params.insurant = insurant;
                params.createDate=createDate;
                params.updateDate=updateDate;
                if ("请选择" == orderstatus) {
                    orderstatus = null;
                }
                params.channelStatus = orderstatus;
            }
        },
        "columns": [
            {
                "data": function (data, type, set) {
                    if (data.ordNum == null) {
                        return "待生成保单号";
                    }
                    return data.ordNum;
                },
                "bSortable": false
            },
            {"data": "ordCode", "bSortable": false, "bVisible": false},
            {
                "data": function (row, type, set) {
                    if (row.insurant == null) {
                        return "--";
                    }
                    return row.insurant;
                },
                "bSortable": false
            },
            {
                "data": function (row, type, set) {
                    if (row.plateNum == null) {
                        return "--";
                    }
                    return row.plateNum;
                }, "bSortable": false
            },//"bSortable",默认为true,表示是否在某一列上开启排序
            {
                "data": function (row, type, set) {
                    if (row.frameNumber == null) {
                        return "--";
                    }
                    return row.frameNumber;
                }, "bSortable": false,
            },
            {"data": "insyrerName", "bSortable": false, "defalutContent": '--'},
            {
                // 定义操作列,######以下是重点########
                // "targets" : 5,//是操作按钮目标列
                // "data" : null,
                "render": function (data, type, row) {
                    if(row.typeInsurance==null){
                        return "--"
                    }
                    if (row.typeInsurance == 0) {
                        var html = "交强险"
                    } else {
                        var html = "商业险"
                    }
                    return html;
                }
            },
            {
                "data": function (row, type, set) {
                    if (row.mercialPremium == null) {
                        return "--";
                    }
                    return row.mercialPremium;
                },
                "bSortable": false, "sClass": "text-right", "defaultContent": '--'
            },
            {
                "data": function (row, type, set) {
                    if (row.pulsoryPremium == null) {
                        return "--";
                    }
                    return row.pulsoryPremium;
                }, "bSortable": false, "sClass": "text-right", "defaultContent": '--'
            },
            {
                "data": function (row, type, set) {
                    if (row.vechcleVesselTax == null) {
                        return "--";
                    }
                    return row.vechcleVesselTax;
                },
                "bSortable": false, "sClass": "text-right", "defaultContent": '--'
            },
            {"data": "allPremium", "bSortable": false, "sClass": "text-right", "defaultContent": '--'},
            {"data": "mustPremium", "bSortable": false, "sClass": "text-right", "defaultContent": '--'},
            {"data": "channelRebate", "bSortable": false, "sClass": "text-right", "defaultContent": '--'},
            {"data": "mustRebateAmt", "bSortable": false, "sClass": "text-right", "defaultContent": '--'},
            {"data": "realRebateAmt", "bSortable": false, "sClass": "text-right", "defaultContent": '--'},
            // { "data": "insyrerMaturityDate" ,"bSortable": false},
            {
                // 定义操作列,######以下是重点########
                // "targets" : 5,//是操作按钮目标列
                // "data" : null,
                "render": function (data, type, row) {
                    return convertTime(row.insyrerMaturityDate);
                }
            },
            {
                "render": function (data, type, row) {
                    if(row.channelStatus==null){
                        return "--"
                    }
                    //在columnDefs中,data取值和row是一样的
                    if (row.channelStatus == 1) {
                        var message = "待审核";
                    } else if (row.channelStatus == 2) {
                        var message = "待支付";
                    } else if (row.channelStatus == 3) {
                        var message = "待生成保单";
                    } else if (row.channelStatus == 4) {
                        var message = "待确认定价";
                    } else if (row.channelStatus == 5) {
                        var message = "已拒绝定价";
                    } else if (row.channelStatus == 6) {
                        var message = "被驳回";
                    } else if (row.channelStatus == 7) {
                        var message = "待返佣";
                    } else if (row.channelStatus == 8) {
                        var message = "待还款";
                    } else if (row.channelStatus == 9) {
                        var message = "产品变更";
                    } else if (row.channelStatus == 10) {
                        var message = "授信不足";
                    } else if (row.channelStatus == 11) {
                        var message = "已结算";
                    } else if (row.channelStatus == 12) {
                        var message = "待退保结算";
                    } else if (row.channelStatus == 13) {
                        var message = "已退保结算";
                    } else if (row.channelStatus == 14) {
                        var message = "产品不可用";
                    }else {
                        return "--";
                    }
                    return message;
                }
            }
        ],
        "columnDefs": [
            {
                "targets": 17,//是操作按钮目标列
                "data": null,
                "render": function (data, type, row) {
                    console.log("row.channelStatus" + row.channelStatus)
                    if(row.channelStatus == null){
                        return "--";
                    }
                    if (row.channelStatus == 6) {
                        //var editOrdercode ="'"+row.ordCode+"'";
                        return '<a href="#tab2"  data-toggle="tab" onclick="editorder(\''+row.ordCode+'\')">编辑</a>';
                    } else if (row.channelStatus == 4 || row.channelStatus == 9 || row.channelStatus == 10 || row.channelStatus == 14) {
                        return "<a href='/ins/order/confirmprice?tid=" + row.tid + "' >确认定价</a>";
                    } else {
                        return "--";
                    }
                }
            }]
    });
});
function search() {
    table.ajax.reload();
}
//确认定价tab转换
// function comfirmprc(ordCode){
//     $.ajax({
//         url:"/ins/order/confirmpri",
//         data:{"ordCode":ordCode},
//         sucess:
//     })
// }
function convertTime(time) {
    if (typeof (time) == "undefined") {
        return "--";
    }
    if (time == null) {
        return "--";
    }

    return time;
}
//补0操作,当时间数据小于10的时候，给该数据前面加一个0
function getzf(num) {
    if (parseInt(num) < 10) {
        num = '0' + num;
    }
    return num;
}

/*-------------------------------------编辑订单回显------------------------------------*/
function editorder(ordercode) {
    console.log()
    $.ajax({
        type: "POST",
        url: "/ins/order/findord",
        data: {"ordercode": ordercode},
        success: function (result) {
            var data =result.data
            var item = "<option value= ''>请选择</option>\n";
            if (data.typeInsurance == 0) {
                console.log(data.typeInsurance)
                $("#typeInsurance0").val(0)
                $("#typeInsurance1").removeAttr("checked")
                $("#typeInsurance0").attr("checked", "checked")
                $("#precompanyId").hide()
                $("#engineNum").show()
            }
            if (data.typeInsurance == 1) {
                console.log(data.typeInsurance)
                $("#typeInsurance1").val(1)
                $("#typeInsurance0").removeAttr("checked")
                $("#typeInsurance1").attr("checked", "checked")
                $("#precompanyId").show()
                $("#engineNum").hide()
            }
            $("#orderTid1").val(data.tid)
            $("#ordCode").val(data.ordCode);
            $("#preInsyrer").val(data.preInsyrer);
            $("#companyId").val(data.companyId);
            $("#productId").val(data.productId)
            $("#carOwner1").val(data.carOwner);
            $("#plateNum").val(data.plateNum);
            $("#frameNumber").val(data.frameNumber)
            $("#engineNum1").val(data.engineNum)
            $("#insurant1").val(data.insurant)
            $("#orgIdCode").val(data.orgIdCode)
            $("#insureStartDate").val(data.insureStartDate)
            $("#insureEndDate").val(data.insureEndDate)
            var zhangqi=data.laonAccount;
            $("#baoxiangongsi0").addClass("hidden","hidden")
            $("#baoxiangongsi1").removeClass("hidden")
            var typeInvestment=data.typeInvestment;
            console.log("typeInvestment"+typeInvestment)
            if(typeInvestment==0){
                $("#typeInsurance1").removeAttr("checked");
                $("#typeInsurance0").attr("checked", "checked");
                $("#carOwner1").attr("data-parsley-required",true);
                $("#carOwner1").attr("data-parsley-required-message","车主不能为空");
                $("#preInsyrer").attr("type", "hidden");
                $("#engineNum").removeClass("hidden");
                $("#engineNum1").removeAttr("type");
                $("#engineNum").show();
                $("#precompanyId").hide();
                $("#plateNum").removeAttr("data-parsley-required");
                $("#plateNum").removeAttr("data-parsley-required-message");
                $("#insurant1").attr("data-parsley-required",true);
                $("#insurant1").attr("data-parsley-required-message","被保险人不能为空");
                $("#orgIdCode").attr("data-parsley-required",true);
                $("#orgIdCode").attr("data-parsley-required-message","被保人身份信息不能为空");
            }
            if(typeInvestment==1){
                $("#typeInsurance0").removeAttr("checked");
                $("#typeInsurance1").attr("checked", "checked");
                $("#carOwner1").removeAttr("data-parsley-required");
                $("#carOwner1").removeAttr("data-parsley-required-message");
                $("#engineNum1").attr("type", "hidden");
                $("#preInsyrer").removeAttr("type");
                $("#precompanyId").show();
                $("#engineNum").hide();
                $("#plateNum").attr("data-parsley-required",true);
                $("#plateNum").attr("data-parsley-required-message","车牌号不能为空");
                $("#insurant1").removeAttr("data-parsley-required");
                $("#insurant1").removeAttr("data-parsley-required-message");
                $("#orgIdCode").removeAttr("data-parsley-required");
                $("#orgIdCode").removeAttr("data-parsley-required-message");
            }
            $("#baoxiangongsi2").html(data.insyrerName);
            var typeInsurance=data.typeInsurance;
            if(typeInsurance==0){
                $("#xianzhong1").removeClass("hidden")
                $("#xianzhong2").html("交强险")
            }
            if(typeInsurance==1){
                $("#xianzhong1").removeClass("hidden")
                $("#xianzhong2").html("商业险")
            }
            var insval = data.insyrerId;
            $('#companyIdd option').each(function () {
                var optionval = $(this).val();
                if (insval != optionval) {
                    $(this).removeAttr("selected")
                } else {
                    $(this).attr("selected", "selected")
                }
            })
            var cartype = data.vehicleType;
            if (cartype == 1) {
                $("#vehicleType1").val(1)
                $("#vehicleType2").removeAttr("checked")
                $("#vehicleType1").attr("checked", "checked")
            }
            if (cartype == 2) {
                $("#vehicleType2").val(2)
                $("#vehicleType1").removeAttr("checked")
                $("#vehicleType2").attr("checked", "checked")
            }
            var instype = data.typeInsurance2;
            var ordstaus = data.status;
            $("#statusord").val(ordstaus)
            if (ordstaus <= 0) {
                $("#typeInsurance12").show();
                $("#typeInsurance23").show();
            } else {
                if (instype == 1) {
                    $("#typeInsurance23").hide()
                    $("#typeInsurance21").val(1)
                    $("#typeInsurance21").attr("checked", "checked")
                }
                if (instype == 2) {
                    $("#typeInsurance12").hide()
                    $("#typeInsurance22").val(2)
                    $("#typeInsurance22").attr("checked", "checked")
                }
            }
            $("#insyrerName").val(data.insyrerName)
            $("#applicant").val(data.applicant)
            var investmentType = data.typeInsurance2
            var laonAcc = data.typeInsurance2;
            $("#typeInvestment option").each(function () {
                var optvalue = $(this).val()
                if (investmentType == optvalue) {
                    $(this).attr("selected", "selected")
                    if (investmentType == 3) {
                        $("#laonAccount").removeAttr("hidden")
                        var earingPointList=result.products;
                            for(var i in earingPointList){
                                if(earingPointList[i].type==3){
                                    console.log("~~~~~~~~~~~~~~~~~~~"+earingPointList[i].paymentDays)
                                    item += "<option value='" + earingPointList[i].paymentDays + "'>" + "账期" + earingPointList[i].paymentDays + "天" + "</option>\n";
                                }
                            }
                            $("#laonAccount1").html(item)
                            $("#laonAccount1").val(zhangqi)
                        // $.each(earingPointList,function (itemss) {
                        //     console.log("itemss--------------------"+itemss.paymentDays)
                        // })

                        //$("#laonAccount").show()
                        $("#laonAccount1 option").each(function () {
                            var loanterm = $(this).val();
                            if (laonAcc == loanterm) {
                                $(this).attr("selected", "selected")
                            }
                        })
                    }
                }
            })
        }
    })
    $("#new-edit").val(77)
    $("#tabEdit").removeClass("hidden").trigger("click")
}
function exporttables() {
    $("#downloadstyle").html("确认下载当前列表信息");
    $("#download-dialog").modal('show')
}


function downloadord() {
    var ordNum = $("#baodanhao").val();
    var insurant = $("#beibaoxian").val();
    var insureStartDate = $("#dingdantime").val();
    var orderstatus = $("#ordstatus option:selected").val();
    //添加额外的参数传给服务器
    if ("请选择" == orderstatus) {
        orderstatus = null;
    }
    location.href = "/ins/order/export?ordNum=" + ordNum + "&insurant=" + insurant + "&insureStartDate=" + insureStartDate + "&orderstatus=" + orderstatus + "&flag=" + "1";
    $("#dwload").modal('hide');
    // table.ajax.reload();
    // console.log("-------------------------------------------------")
}
//提示模态框
function confirmModel() {
    $("#form_id").submit()
    $('#form_id').parsley().whenValidate({}).done(function () {
        $("#modal-confirmvalue").modal().show()
        $("#confirmbutton").html("确认该定价?")
    });
}
//同意确认定价
function argeePayState() {
    var orderCode=$("#orderCode").val();
    var orderTid = $("#orderTid").val();
    var message = $("#ord_message").val();
    console.log("orderCode-------------------->" + orderCode)
    console.log("message-------------------->" + message)
    $("#disbutton").attr("disabled", "disabled");
    location.href = "/ins/order/agreePayState?orderTid=" + orderTid + "&orderMark=" + message;
}

//拒绝确认定价
function refuseprice() {
    console.log("===============================================")
    var orderCode=$("#orderCode").val();
    var orderTid = $("#orderTid").val();
    var message = $("#ord_message").val();
    location.href = "/ins/order/refusePayState?orderTid=" + orderTid + "&orderMark=" + message;
    console.log("===============================================")
}
//新建订单取消按钮
function newcancel() {
        // $("#tab1").removeClass("active in")
        // $("#tab2").removeClass("active in")
        // $("#tab3").removeClass("active in")
        // $("#tab1").addClass("active in")
        // $("#tabEdit").addClass("hidden");
        location=location;
}

// ***********************************校验************************************
// 只能为汉字或字符
window.ParsleyValidator.addValidator('personname', function (value) {
    if (value != "") {
        return /^[\u4e00-\u9fa5A-Za-z]+$/.test(value);
    }
    return true;
}, 32);
// 只能为数字或字母
// window.ParsleyValidator.addValidator('nzcheck', function (value) {
//     if (value != "") {
//         return /^[a-zA-Z0-9]+$/.test(value);
//     }
//     return true;
// }, 32);

window.ParsleyValidator.addValidator('zimucheck', function (value) {
    if (value != "") {
        return (/^[a-zA-Z0-9]+$/.test(value));
    }
    return true;
}, 32);
//小数校验
window.ParsleyValidator.addValidator('point', function (value) {
    if (value != "") {
        //return /^[+]{0,1}(\d{1,2})$|^[+]{0,1}(\d{1,2}\.\d{1,2})$/.test(value);
        return /^[1-9][0-9]*$/.test(value)
    }
    return true;
}, 32);

var pattern = new RegExp("[`~@#$^&*()=|\\[{}\\]<>/~#￥……&*（）——|【】%+ 　\\\\\]");

window.ParsleyValidator.addValidator('specialchar', function (value) {
    if (value != "") {
        //return /^[+]{0,1}(\d{1,2})$|^[+]{0,1}(\d{1,2}\.\d{1,2})$/.test(value);
        return !/[`~@#$^&*()=|\[{}\]<>/~#￥……&*（）——|《》！，。？?·!,.:;：；“”‘’"'’‘、/【】%+ 　\\]+/g.test(value)
    }
    return true;
}, 32);
/*编辑----新建切换清空数据*/
$("#newflush").click(function () {
    $("#tab2 input").val("")
    $("#typeInsurance1").val(1)
    $("#typeInsurance0").val(0)
    $("#vehicleType1").val(1)
    $("#vehicleType1").val(2)
    $("#tabEdit").addClass("hidden")
    $("#new-edit").val(55)
    $("#baoxiangongsi0").removeClass("hidden")
    $("#companyIdd").val("")
    $("#baoxiangongsi1").addClass("hidden")
    $("#xianzhong1").addClass("hidden")
    var datenum = new Date().getTime();
    var enddatetime = datenum + 365 * 24 * 60 * 60 * 1000;
    var date = new Date(datenum)
    var enddate = new Date(enddatetime)
    date1 = dateFtt("yyyy-MM-dd", date)
    enddate1 = dateFtt("yyyy-MM-dd", enddate)
    $("#insureStartDate").val(date1)
    $("#insureEndDate").val(enddate1)
    $("#dateIssuance").val(date1);
    $("#typeInvestment").val("")
})

/*编辑垫资期限相关回显*/
$("#typeInvestment").click(function () {
    $("#productId").val();
    var value1 =$("#typeInvestment option:selected").val();
    if(value1==3){
        $("#laonAccount1").attr("data-parsley-required",true);
        $("#laonAccount1").attr("data-parsley-required-message","请选择垫资期限");
    }else{
        $("#laonAccount1").removeAttr("data-parsley-required");
        $("#laonAccount1").removeAttr("data-parsley-required-message");
    }
})

/*编辑提交，校验产品是否过期*/
function editsubmit() {
    var value =$("#new-edit").val();
    var productId=$("#productId").val()
    var orderId =$("#orderTid1").val()
    if(value==55){
        return true;
    }
    if(value==77){
        $.ajax({
            type:"POST",
            url:"/product/checkedy",
            data:{"productId":productId},
            dataType:"json",
            success:function (data) {
                console.log("data"+data)
                console.log("data.rebateSetVo.status"+data.result.status)
                var  status=data.result.status;
                if(status==0){
                    return true;
                }
                if(status==1){
                    alert("该产品不可用")
                    return false;
                }
                /*状态为2，表示老产品不可用,订单列表需要修改productId*/
                if(status==2){
                    var dianziqixian=$("#typeInvestment option:selected").val();
                    if(dianziqixian==3){
                        $("#laonAccount1").attr("data-parsley-required",true);
                        $("#laonAccount1").attr("data-parsley-required-message","请选择垫资期限");
                        /* 需要重新刷新产品信息*/
                        $("#laonAccount1").html("")
                        var item = "<option value= ''>请选择</option>\n";
                        var value1=data.result.list;
                        $.each(value1,function (index,value) {
                            item += "<option value='" + value.paymentDays + "'>" + "账期" + value.paymentDays + "天" + "</option>\n";
                        })
                        $("#laonAccount1").append(item)
                        alert("产品已过期，请重新选择！！！！")
                    }else{
                        $("#laonAccount1").removeAttr("data-parsley-required");
                        $("#laonAccount1").removeAttr("data-parsley-required-message");
                    }
                    var product1 = data.result.productId;
                    $.ajax({
                        type:"post",
                        url:"/ins/order/modify/productid",
                        data:{"orderId":orderId,"productId":product1},
                        dataType:"json",
                        success:function (data1) {
                            if(data1.type==1){
                                console.log("产品修改成功！！！")
                                return true;
                            }else {
                                alert("产品更改失败！！！");
                            }
                        }
                    })
                }
            }
        })
    }
}